import { Module } from "@nestjs/common";
import { TypeOrmModule } from "@nestjs/typeorm";
import { DataSource } from "typeorm";
import { ConfigModule, ConfigService } from "@nestjs/config";
import configuration from "./config/configuration";
import { ApiModule } from "./api/api.module";
// import { UserEntity } from "./modules/common/user.module/user.entity";
import { Database } from "./database";
import { JwtModule } from "@nestjs/jwt";
import { JwtStrategy } from "./common/strategies/jwt.strategy";
import { APP_GUARD, RouterModule } from "@nestjs/core";
import { JwtAuthGuard } from "./common/guards/auth.guard";
import { ServeStaticModule } from "@nestjs/serve-static";
import { join } from "path";
import { SysModule } from "../modules/sys-module/sys.module";

@Module({
  imports: [
    SysModule,
    // 注入全局配置文件
    ConfigModule.forRoot({
      isGlobal: true,
      load: [configuration]
    }),
    // 注入TypeOrm
    // TypeOrmModule.forRootAsync({
    //   imports: [ConfigModule],
    //   inject: [ConfigService],
    //   useFactory: async (configService: ConfigService) => ({
    //     ...configService.get("DATABASE_CONFIG")[0]
    //   })
    // }),
    // 注入Jwt
    // JwtModule.registerAsync({
    //   imports: [ConfigModule],
    //   inject: [ConfigService],
    //   useFactory: async (configService: ConfigService) => ({
    //     ...configService.get("JWT_CONFIG")
    //   })
    // }),
    // 注入静态资源模块
    ServeStaticModule.forRoot({
      rootPath: join(__dirname, "../", "public")
    }),
    // ApiModule,
    // RouterModule.register([
    //   { path:"api",module: ApiModule }
    // ])
  ],
  controllers: [],
  // providers: [JwtStrategy, { provide: APP_GUARD, useClass: JwtAuthGuard }]
})
export class AppModule {}

// export const AppDataSource = new DataSource({
//   ...configuration().DATABASE_CONFIG[0],
//   entities: [UserEntity]
// });
(async () => {
  // 初始化DataSource
  // await AppDataSource.initialize();
  // // 初始化Database
  // await new Database().initData();
})();
